import java.io.*;
import java.lang.*;

public class tester extends Thread{
    Pipe p;
    int x;
    BufferedWriter out;
    public tester(Pipe p,int x){
        this.p = p;
        this.x =x;
        try{
           
            out = new BufferedWriter(new FileWriter("pipe.dat"));
            out.write("##########################################\n\n");
            out.write("Pipe test1\n");
            out.write("\n##########################################\n");
            out.write("Test: Writer thread writes 1023 char to the array,\n");
            out.write("reader thread reads all of the values from the buffer\n\n");
        }catch(Exception e){}
    }
    public void run(){
        try{
        
        if(x == 1){
        
            p.writePipe("this is a test of alot of the different I want to make this test longer than 1024 char so that it will test this programs ability to be patient\n"));
            p.writePipe("this is a test of alot of the different I want to make this test longer than 1024 char so that it will test this programs ability to be patient\n"));
            p.writePipe("this is a test of alot of the different I want to make this test longer than 1024 char so that it will test this programs ability to be patient\n"));
            p.writePipe("this is a test of alot of the different I want to make this test longer than 1024 char so that it will test this programs ability to be patient\n"));
            p.writePipe("this is a test of alot of the different I want to make this test longer than 1024 char so that it will test this programs ability to be patient\n"));
            p.writePipe("this is a test of alot of the different I want to make this test longer than 1024 char so that it will test this programs ability to be patient\n"));
        }else if(x ==2){
            out.write(p.readPipe(1024));
            out.close();
        }
        else{
            try{
                sleep(100);
                }catch(Exception e){}
          p.closePipe();
        }
        }catch(Exception e){}
        
    }

}
